package com.oocl.chatroom.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.oocl.service.UserService;
import com.oocl.service.impl.UserServiceImpl;

public class ChatServer extends ServerSocket{
       
	private Map<String,OnlineSocket> users;
	private UserService userService;
	public static boolean RUNNING;
	long startTime ;
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	
	public ChatServer(int port) throws IOException {
		super(port);
		userService = new UserServiceImpl();
		RUNNING = true;
	}

	public void initUsersMap(){
		List<String> names = userService.loadNames();
		startTime = new Date().getTime();
		users = new HashMap<String,OnlineSocket>();
		for(String name:names){
			users.put(name, null);
		}
	}
	
	


	public void setRunning(boolean RUNNING) {
		this.RUNNING = RUNNING;
	}


	public Map<String, OnlineSocket> getUsers() {
		return users;
	}

	public void setUsers(Map<String, OnlineSocket> users) {
		this.users = users;
	}


	public long getStartTime() {
		return startTime;
	}


	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}
	

}
